'use strict';

const Controller = require( 'egg' ).Controller;

const createRule = {
    username: {
        type: 'email',
    },
    password: {
        type: 'password',
        compare: 're-password',
    },
};

class HomeController extends Controller {
    async index(ctx) {

        this.logger.debug("is ios",ctx.isIOS);
        this.logger.debug(ctx.__("Email"));

        this.logger.debug("ips is ",ctx.ips);
        ctx.cookies.set("name","ryan");

        /* await this.app.redis.set("test",1);

         this.logger.debug(await this.app.redis.get("test"));*/
         ctx.session.name="ryan";
        /*ctx.body= await ctx.renderString('{{ name | title }}', { name: 'egg' });
        this.logger.debug(ctx.body);*/

        await ctx.render( "home.html", {
            user : {
                name: ctx.helper.formatName("chen"),
            },
            title: 'egg view example',
        } )
    }

    async page(ctx)
    {
        this.logger.debug(ctx.session.name);
        await ctx.render("page1.html",{});
    }

    async user(ctx)
    {

        this.logger.debug(ctx);

        await ctx.validate(createRule);

        this.logger.debug("ip is ",ctx.ip);
        this.logger.debug("name is ",ctx.cookies.get("name"));

        //ctx.set("content_type","");  //设置header
        ctx.body ="ryan";

        //ctx.redirect("");
        //ctx.getFileStream()
    }
}


module.exports = HomeController;
